package algorithm;

public class IdMaker {

    private static IdMaker instance;
    private int id=-1;

    private IdMaker(){

    }

    // synchronized 是互斥锁
    public static synchronized IdMaker getInstance(){
        if (instance==null)
            instance=new IdMaker();
        return instance;
    }

    public int getId(){
        id++;
        return id;
    }
}
